home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI433.ASC < prev    next >
Text File  |  1991-09-11  |  7KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  TURBO PASCAL                           NUMBER  :  433
  9.   VERSION  :  4.0
  10.        OS  :  PC-DOS 2.X, 3.X
  11.      DATE  :  MAY 2, 1988                              PAGE  :  1/4
  12.  
  13.     TITLE  :  PRINTING GRAPHICS TO AN EPSON COMPATIBLE PRINTER
  14.  
  15.  
  16.  
  17.  
  18.   { The  following example routines are public domain programs }
  19.   { that have  been uploaded to our Forum on CompuServe.  As a }
  20.   { courtesy to our users that  do not have  immediate  access }
  21.   { to  CompuServe,  Technical   Support   distributes   these }
  22.   { routines free of charge.                                   }
  23.   {                                                            }
  24.   { However, because these routines are public domain programs,}
  25.   { not developed  by Borland International,  we are unable to }
  26.   { provide any  Technical  Support or  assistance using these }
  27.   { routines. If you need assistance  using  these   routines, }
  28.   { or   are   experiencing difficulties,  we  recommend  that }
  29.   { you log onto CompuServe  and request  assistance  from the }
  30.   { Forum members that developed  these routines.              }
  31.  
  32.   Unit GraphPRN;
  33.  
  34.   { This  unit is  designed to send  graphics images  to Epson }
  35.   { Compatible  and  late  model  IBM  ProPrinter  Dot  Matrix }
  36.   { printers.  It takes the  image from  the currently  active }
  37.   { Viewport, determined  by  a call  to  GetViewSettings, and }
  38.   { transfers that image to the printer.                       }
  39.  
  40.   Interface
  41.  
  42.   Uses Dos, Graph;     { Used to get the Image from the Screen }
  43.  
  44.   Var
  45.      LST : Text;
  46.  
  47.   Procedure HardCopy (Gmode: Integer);
  48.   { Procedure HardCopy prints the current ViewPort    }
  49.   {   To an IBM or Epson compatible graphics printer. }
  50.   {                                                   }
  51.   { Valid Gmode numbers are :                         }
  52.   {     -4 to -1 for Epson and IBM Graphic Printers   }
  53.   {      0 to 7  for Epson Printers                   }
  54.  
  55.   Implementation
  56.  
  57.   Procedure HardCopy {Gmode: Integer};
  58.  
  59.   Const
  60.      Bits : Array [0..7] of Byte = (128,64,32,16,8,4,2,1);
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  TURBO PASCAL                           NUMBER  :  433
  75.   VERSION  :  4.0
  76.        OS  :  PC-DOS 2.X, 3.X
  77.      DATE  :  MAY 2, 1988                              PAGE  :  2/4
  78.  
  79.     TITLE  :  PRINTING GRAPHICS TO AN EPSON COMPATIBLE PRINTER
  80.  
  81.  
  82.  
  83.  
  84.   Var
  85.       X,Y,YOfs        : Integer;   { Screen  location variables }
  86.       BitData,MaxBits : Byte;      { Number of Bits to transfer }
  87.       Vport           : ViewPortType;{Used to get view settings }
  88.       Height, Width   : Word;      { Size of image  to transfer }
  89.       HiBit, LoBit    : Char;      {     Char size of image     }
  90.       LineSpacing,                 { Additional  Info for  dump }
  91.       GraphixPrefix   : String[10];{      "        "   "     "  }
  92.  
  93.   Begin
  94.     LineSpacing   := #27+'3'+#24; { 24/216 inch line spacing    }
  95.     Case Gmode Of
  96.          -1: GraphixPrefix := #27+'K'; { Std. Density           }
  97.          -2: GraphixPrefix := #27+'L'; { Double Density         }
  98.          -3: GraphixPrefix := #27+'Y'; { Dbl. Density Dbl. Speed}
  99.          -4: GraphixPrefix := #27+'Z'; { Quad. Density          }
  100.        0..7: GraphixPrefix := #27+'*'+Chr(Gmode);{ 8-Pin Bit Img}
  101.       Else
  102.        Exit;                           { Invalid Mode Selection }
  103.     End;
  104.     GetViewSettings( Vport );          { Get  size  of image to }
  105.     Height := Vport.Y2 - Vport.Y1;     { be printed             }
  106.     Width  := ( Vport.X2 + 1 ) - Vport.X1;
  107.     HiBit := Chr(Hi(Width));           {Translate sizes to char }
  108.     LoBit := Chr(Lo(Width));           { for  output to printer }
  109.     Write( LST, LineSpacing );
  110.     Y := 0;
  111.     While Y < Height Do
  112.     Begin
  113.        Write( LST,GraphixPrefix,LoBit,HiBit );
  114.        For X := 0 to Width-1 Do
  115.        Begin
  116.           BitData := 0;
  117.           If y + 7 <= Height
  118.             Then MaxBits := 7
  119.           Else
  120.             MaxBits := Height - Y;
  121.           For YOfs := 0 to MaxBits do
  122.           Begin
  123.            If GetPixel( X, YOfs+Y ) > 0
  124.              Then BitData := BitData or Bits[YOfs];
  125.           End;
  126.           Write( LST, Chr(BitData) );
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  TURBO PASCAL                           NUMBER  :  433
  141.   VERSION  :  4.0
  142.        OS  :  PC-DOS 2.X, 3.X
  143.      DATE  :  MAY 2, 1988                              PAGE  :  3/4
  144.  
  145.     TITLE  :  PRINTING GRAPHICS TO AN EPSON COMPATIBLE PRINTER
  146.  
  147.  
  148.  
  149.  
  150.        End;
  151.        WriteLn ( LST );
  152.        Inc(Y,8);
  153.     End;
  154.   End;
  155.  
  156.   {$F+}
  157.  
  158.   {      LSTNoFunction performs a NUL operation for a Reset or  }
  159.   { Rewrite on LST (Just in case)                               }
  160.  
  161.   Function LSTNoFunction( Var F: TextRec ): integer;
  162.   Begin
  163.     LSTNoFunction := 0;                    { No error           }
  164.   end;
  165.  
  166.   {      LSTOutputToPrinter sends the output to the Printer     }
  167.   { port number stored in the first byte of the UserData area   }
  168.   { of the Text Record.                                         }
  169.  
  170.   Function LSTOutputToPrinter( Var F: TextRec ): integer;
  171.   var
  172.     Regs: Registers;
  173.     P : word;
  174.   begin
  175.     With F do
  176.     Begin
  177.       P := 0;
  178.       Regs.AH := 16;
  179.       While (P < BufPos) and ((regs.ah and 16) = 16) do
  180.       Begin
  181.         Regs.AL := Ord(BufPtr^[P]);
  182.         Regs.AH := 0;
  183.         Regs.DX := UserData[1];
  184.         Intr($17,Regs);
  185.         Inc(P);
  186.       end;
  187.       BufPos := 0;
  188.     End;
  189.     if (Regs.AH and 16) = 16 then
  190.       LSTOutputToPrinter := 0              { No error           }
  191.      else
  192.        if (Regs.AH and 32 ) = 32 then
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  TURBO PASCAL                           NUMBER  :  433
  207.   VERSION  :  4.0
  208.        OS  :  PC-DOS 2.X, 3.X
  209.      DATE  :  MAY 2, 1988                              PAGE  :  4/4
  210.  
  211.     TITLE  :  PRINTING GRAPHICS TO AN EPSON COMPATIBLE PRINTER
  212.  
  213.  
  214.  
  215.  
  216.          LSTOutputToPrinter := 159         { Out of Paper       }
  217.      else
  218.          LSTOutputToPrinter := 160;        { Device write Fault }
  219.   End;
  220.  
  221.   {$F-}
  222.  
  223.   {      AssignLST both sets up the LST text file record as     }
  224.   { would ASSIGN, and initializes it as would a RESET.  It also }
  225.   { stores the Port number in the first Byte of the UserData    }
  226.   { area.                                                       }
  227.  
  228.   Procedure AssignLST( Port:Byte );
  229.   Begin
  230.     With TextRec(LST) do
  231.       begin
  232.         Handle      := $FFF0;
  233.         Mode        := fmOutput;
  234.         BufSize     := SizeOf(Buffer);
  235.         BufPtr      := @Buffer;
  236.         BufPos      := 0;
  237.         OpenFunc    := @LSTNoFunction;
  238.         InOutFunc   := @LSTOutputToPrinter;
  239.         FlushFunc   := @LSTOutputToPrinter;
  240.         CloseFunc   := @LSTOutputToPrinter;
  241.         UserData[1] := Port - 1;  { We subtract one because }
  242.     end;                          { Dos Counts from zero.   }
  243.   end;
  244.  
  245.  
  246.  
  247.   Begin
  248.      AssignLST( 1 );           { Sets output printer to LPT1 by }
  249.                                { default.  Change this value to }
  250.                                { a 2 to select LPT2.            }
  251.   End.                         { Note: BIOS only handles LPT1   }
  252.                                               {      and      LPT2.
  253.   }
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.